package com.zhiyou100.controller;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


import com.zhiyou100.model.Course;

import com.zhiyou100.model.Selector;
import com.zhiyou100.model.Speaker;
import com.zhiyou100.model.SubjectVo;
import com.zhiyou100.model.Video;
import com.zhiyou100.service.CourseService;
import com.zhiyou100.service.SpeakerService;
import com.zhiyou100.service.SubjectService;
import com.zhiyou100.service.VideoService;



@Controller
public class CourseController {

	@Autowired
	private CourseService service;
	@Autowired
	private SpeakerService speakerService;
	@Autowired
	private SubjectService subjectService;
	@Autowired
	private CourseService cService;
	@Autowired
	private VideoService vService;
	
	@RequestMapping("/list")
	public String listCourse(Long subjectId, HttpServletRequest request,Model model) {
		
		
		List<Course> list=service.listBySid(subjectId);
		
		String suName=subjectService.getSubject(subjectId);
		
		model.addAttribute("suName", suName);
		
		model.addAttribute("subjectId",subjectId);
		
		//System.out.println(list.size());
		
		model.addAttribute("list", list);
		
		return "subject";
	}
	
	@RequestMapping("/listvideo")
	public String listVideo(Long videoId,Long courseId, String suName, HttpServletRequest request,Model model) {
		
		
		Speaker speaker=speakerService.getSpeaker(videoId);
		
		Course course=cService.getCourse(courseId);
		
		List<Video> list=vService.listByC(courseId);
		
		model.addAttribute("course", course);
		
		model.addAttribute("list",list);
		
		model.addAttribute("speaker", speaker);
		
		System.out.println(suName);
		
		model.addAttribute("suName", suName);
		
		return "section";
	}
	
	
	
}
